package com.example.myapplication;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class LayoutParamsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //代替这个
//        setContentView(R.layout.activity_main5);

        LinearLayout linearLayout = new LinearLayout(this);   //线性布局

        TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewGroup.LayoutParams layoutParams1 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearLayout.setLayoutParams(layoutParams1);      //设置线性布局的宽高

        //创建一个TextView
        TextView textView = new TextView(this);
        textView.setText("一句话吧就");
        textView.setBackgroundColor(R.color.Pink);
        TableRow.LayoutParams textViewLayoutParams = new TableRow.LayoutParams(300, 60);  //注意这里只能是像素值

//        textView.setLayoutParams(textViewLayoutParams);
//        linearLayout.addView(textView);

        linearLayout.addView(textView, textViewLayoutParams);   //这个方法可以在在inflate中看到，

        setContentView(linearLayout);

    }
}